package com.niodata.dp.task.dao;

import com.niodata.dp.task.entity.TaskMonitorConfig;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TaskMonitorConfigMapper {

  @Select("select * from TASK_MONITOR_CONFIG")
  @ResultMap("taskMonitorConfigResultMap")
  public List<TaskMonitorConfig> getTaskMonitorLis();

  @Select("select * from TASK_MONITOR_CONFIG where TASK_NAME = #{taskName}")
  @ResultMap("taskMonitorConfigResultMap")
  public TaskMonitorConfig getTaskMonitorByTaskName(String taskName);

  @Insert(
      "insert into TASK_MONITOR_CONFIG(ID,TASK_ID,TASK_NAME,ALERT_RULE,"
          + "USER_INFO,UPDATE_TIME,CREATE_TIME)"
          + "values(#{taskMonitorConfig.id},#{taskMonitorConfig.taskId},"
          + "#{taskMonitorConfig.taskName},"
          + "#{taskMonitorConfig.alertRule},#{taskMonitorConfig.userInfo},"
          + "#{taskMonitorConfig.updateTime},#{taskMonitorConfig.createTime})")
  public void saveTaskMonitorConfig(@Param("taskMonitorConfig")
      TaskMonitorConfig taskMonitorConfig);

  @Update(
      "update TASK_MONITOR_CONFIG set ALERT_RULE = #{taskMonitorConfig.alertRule},"
          + "USER_INFO=#{taskMonitorConfig.userInfo},"
          + "UPDATE_TIME=#{taskMonitorConfig.updateTime "
          + "where TASK_NAME=#{taskMonitorConfig.taskName}) ")
  public void updateTaskMonitorConfig(@Param("taskMonitorConfig")
      TaskMonitorConfig taskMonitorConfig);

  @Delete("delete from TASK_MONITOR_CONFIG where TASK_NAME=#{taskName}")
  public void deleteTaskMonitorConfig(@Param("taskName") String taskName);

}
